<template>
  <div class="ma-content-block lg:flex justify-between p-4">
    <!-- CRUD 组件 -->
    <ma-crud :options="options" :columns="columns" ref="crudRef">
    </ma-crud>
  </div>
</template>
<script setup>
import { ref, reactive } from 'vue'
import goodsManage from '@/api/goods/goodsManage'
import { Message } from '@arco-design/web-vue'
import tool from '@/utils/tool'
import * as common from '@/utils/common'

const crudRef = ref()


const numberOperation = (newValue, id, numberName) => {
  goodsManage.numberOperation({ id, numberName, numberValue: newValue }).then( res => {
    res.success && Message.success(res.message)
  }).catch( e => { console.log(e) } )
}

const switchStatus = (statusValue, id, statusName) => {
  goodsManage.changeStatus({ id, statusName, statusValue }).then( res => {
    res.success && Message.success(res.message)
  }).catch( e => { console.log(e) } )
}


const options = reactive({
  id: 'flyos_goods_manage',
  rowSelection: {
    showCheckedAll: true
  },
  pk: 'id',
  operationColumn: true,
  operationWidth: 160,
  formOption: {
    viewType: 'modal',
    width: 600
  },
  api: goodsManage.getList,
  recycleApi: goodsManage.getRecycleList,
  add: {
    show: true,
    api: goodsManage.save,
    auth: ['goods:manage:save']
  },
  edit: {
    show: true,
    api: goodsManage.update,
    auth: ['goods:manage:update']
  },
  delete: {
    show: true,
    api: goodsManage.deletes,
    auth: ['goods:manage:delete'],
    realApi: goodsManage.realDeletes,
    realAuth: ['goods:manage:realDeletes']
  },
  recovery: {
    show: true,
    api: goodsManage.recoverys,
    auth: ['goods:manage:recovery']
  },
  import: {
    show: false,
    url: 'goods/manage/import',
    templateUrl: 'goods/manage/downloadTemplate',
    auth: ['goods:manage:import']
  },
  export: {
    show: false,
    url: 'goods/manage/export',
    auth: ['goods:manage:export']
  }
})

const columns = reactive([
  {
    title: "",
    dataIndex: "id",
    formType: "input",
    addDisplay: false,
    editDisplay: false,
    hide: true,
    commonRules: {
      required: true,
      message: "请输入"
    }
  },
  {
    title: "品名类型",
    dataIndex: "type_id",
    formType: "select",
    align: "center",
    formType: 'select',
    search: true,
    dict: {
      // name:'goods_type',
      // 远程通用接口请求，新版代码生成都有一个 remote 接口
      remote: 'goods/type/remote',
      // 指定组件接收的props
      props: { label: 'name', value: 'id' },
      // 开启分页
      openPage: false,
      // 远程请求配置项
      // remoteOption: {
      //     // 按用户名排序
      //     sort: { value: 'desc' }, // 如果不指定排序方式，默认为正序排序
      //     // 设置查询的字段
      //     select: [ 'value', 'label','type_id' ],
      //     // 设置数据过滤as
      //     filter: {
      //       type_id: [ '=', 36 ]
      //     },
      //     // 关联模型
      //     relations: [
            
      //     ]
      // },
      translation:true,
    },
  },
  {
    title: "品名",
    dataIndex: "name",
    formType: "input",
    search: true
  },
  // {
  //   title: "整车装卸费率",
  //   dataIndex: "car_no_price",
  //   align: "center",
  //   formType: 'input',
  // },
  
  {
    title: "备注",
    dataIndex: "remark",
    formType: "input",
    addDisplay: false,
    editDisplay: false,
    hide: true
  },
  {
    title: "状态",
    dataIndex: "status",
    formType: "radio",
    search: true,
    addDefaultValue: '1',
    dict: {
      data: [
        {
          label: "禁用",
          value: "0"
        },
        {
          label: "启用",
          value: "1"
        }
      ],
      translation: true
    }
  },
  {
    title: "创建时间",
    dataIndex: "created_at",
    formType: "date",
    search: false,
    addDisplay: false,
    editDisplay: false,
    hide: true,
    sortable: {
      sortDirections: [
        "ascend",
        "descend"
      ],
      sorter: true
    },
    showTime: true
  },
  {
    title: "更新时间",
    dataIndex: "updated_at",
    formType: "date",
    addDisplay: false,
    editDisplay: false,
    hide: true,
    showTime: true
  },
  {
    title: "删除时间",
    dataIndex: "deleted_at",
    formType: "date",
    addDisplay: false,
    editDisplay: false,
    hide: true,
    showTime: true
  },
  {
    title: "创建者",
    dataIndex: "created_by",
    formType: "input",
    addDisplay: false,
    editDisplay: false,
    hide: true
  },
  {
    title: "更新者",
    dataIndex: "updated_by",
    formType: "input",
    addDisplay: false,
    editDisplay: false,
    hide: true
  }
])
</script>
<script> export default { name: 'goods:manage' } </script>
